package cn.gson.springboot.model.pjos;

import javax.persistence.*;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

@Entity
public class Dept {
    private int deptsId;
    private String deptName;
    private Integer fatherDeptId;
    private  List<Position> position;
    private Collection<Emp> empsByDeptsId;
    private Collection<Target> targetByDeptsId;
    private List<Permissionsset> permissionssetList;



    @ManyToMany
    @JoinTable(name = "dept_psettable",
            joinColumns = {
                    @JoinColumn(name="depts_id")
            },
            inverseJoinColumns = {
                    @JoinColumn(name = "Pset_id")
            })
    public List<Permissionsset> getPermissionssetList() {
        return permissionssetList;
    }

    public void setPermissionssetList(List<Permissionsset> permissionssetList) {
        this.permissionssetList = permissionssetList;
    }

    @OneToMany(cascade={CascadeType.REMOVE},mappedBy="dept")
    public List<Position> getPosition() {
        return position;
    }

    public void setPosition(List<Position> position) {
        this.position = position;
    }


    @Id
    @Column(name = "depts_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY,generator = "seq")
    public int getDeptsId() {
        return deptsId;
    }

    public void setDeptsId(int deptsId) {
        this.deptsId = deptsId;
    }

    @Basic
    @Column(name = "Dept_name")
    public String getDeptName() {
        return deptName;
    }

    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }

    @Basic
    @Column(name = "father_dept_id")
    public Integer getFatherDeptId() {
        return fatherDeptId;
    }


    public void setFatherDeptId(Integer fatherDeptId) {
        this.fatherDeptId = fatherDeptId;
    }
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Dept dept = (Dept) o;
        return deptsId == dept.deptsId &&
                Objects.equals(deptName, dept.deptName);
    }

    @Override
    public int hashCode() {
        return Objects.hash(deptsId, deptName);
    }


    @OneToMany(mappedBy = "deptByDeptsId")
    public Collection<Emp> getEmpsByDeptsId() {
        return empsByDeptsId;
    }

    public void setEmpsByDeptsId(Collection<Emp> empsByDeptsId) {
        this.empsByDeptsId = empsByDeptsId;
    }


    @OneToMany(mappedBy = "deptByDeptsId")
    public Collection<Target> getTargetByDeptsId() {
        return targetByDeptsId;
    }

    public void setTargetByDeptsId(Collection<Target> targetByDeptsId) {
        this.targetByDeptsId = targetByDeptsId;
    }

    @Override
    public String toString() {
        return "Dept{" +
                "deptsId=" + deptsId +
                ", deptName='" + deptName + '\'' +
                '}';
    }
}
